package dao

import (
	"gin_wuwen_back/model"
	"gin_wuwen_back/tool"
)

type ShopDao struct {
	*tool.Orm
}

/*
  @Description: 初始化数据库操作对象
  @return *ShopDao
*/
func NewShopDao() *ShopDao {
	return &ShopDao{tool.Dbengin}

}

/*
  @Description: 操作数据库查询商铺的数据列表
  @receiver tmp
  @param longitude 地理的经度
  @param latitude  地理的纬度
  @return []model.Shop
*/
func (tmp *ShopDao) Queryshops(longitude, latitude float64, keyword string) []model.Shop {
	var shops []model.Shop
	if keyword == "" {
		err := tmp.Engine.Where(" longtitude = ? and latitude = ?", longitude, latitude).Find(&shops)
		if err != nil {
			return nil
		}
		return shops

	} else {
		err := tmp.Engine.Where(" longtitude = ? and latitude = ? and name like ?", longitude, latitude, keyword).Find(&shops)

		if err != nil {
			return nil
		}
		return shops

	}

}


/*
  @Description: 根据商户id查询对应的服务
  @receiver tmp
  @param shopId
  @return []model.Service
*/
func (tmp *ShopDao) QueryServiceByShopId(shopId int64) []model.Service {
	var services []model.Service
	tmp.Table("service").Join("INNER","shop_service","service.id=shop_service.service_id and shop_service.shop_id=?",shopId).Find(&services)

	return services
}
